package nickthissen.iracing.datamodels;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;

import android.os.Parcel;

import com.google.gson.Gson;

public class Forum implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 7654596150460614268L;

    public Forum()
    {
        this.AbbreviatedName = "?";
    }

	public int Id;
	public boolean IsCategoryHeader;
	public String Title;
    public String AbbreviatedName;
	public String Url;
	public String Category;
    public int Topics;
    public int Posts;
    public String LastMessageTime;
    public String LastMessageUrl;
    public String LastMessageUser;
    public String LastMessageUserUrl;    
    public String IconName;
    public boolean IsWatching;
    
    public boolean isUnread()
    {
    	if (this.IconName == null) return false;
    	return this.IconName.contains("unread");
    }
    
    public static Forum fromJson(String json)
    {
    	Gson g = new Gson();
    	ForumDataModel data = g.fromJson(json, ForumDataModel.class);
    	return data.d;
    }
    
    public static ArrayList<Forum> getListFromJson(String json)
    {
    	Gson g = new Gson();
    	ForumListDataModel data = g.fromJson(json, ForumListDataModel.class);
    	return new ArrayList<Forum>(Arrays.asList(data.d));
    }
    
    private class ForumDataModel
    {
    	public Forum d;
    }
    
    private class ForumListDataModel
    {
    	public Forum d[];
    }
}
